<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <meta charset="utf-8">
    <head th:include="include :: header"></head>
    <body class="gray-bg">

        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>

                                <li>
                                    菜单标题：
                                    <input type="text" name="name"/>
                                </li>
                                <li>
                                    菜单的响应动作类型<input type="text" name="menuType"/>
                                </li>

                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                            class="fa fa-search"></i>&nbsp;搜索
                                    </a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                            class="fa fa-refresh"></i>&nbsp;重置
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="wx:menu:add">
                        <i class="fa fa-plus"></i>
                        添加
                    </a>
                    <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editTree()"
                       shiro:hasPermission="wx:menu:edit">
                        <i class="fa fa-edit"></i>
                        修改
                    </a>
                    <a class="btn btn-info" id="expandAllBtn">
                        <i class="fa fa-exchange"></i>
                        展开/折叠
                    </a>
                    <!--
                        <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="wx:menu:remove">
                            <i class="fa fa-remove"></i> 删除
                        </a>
                        <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="wx:menu:export">
                                <i class="fa fa-download"></i> 导出
                         </a>-->
                    <a class="btn btn-warning" onclick="pushMenu()" shiro:hasPermission="wx:weixinMenu:push">
                        <i class="fa fa-cloud-upload"></i> 推送到微信
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
                </div>
            </div>
        </div>
        <div th:include="include :: footer"></div>
        <script th:inline="javascript">
            var prefix = ctx + "wx/menu";
            // 应用菜单
            function pushMenu() {
                $.modal.confirm("确定要应用菜单吗？", function() {
                    $.ajax({
                        type: "get",
                        url:  prefix + "/pushMenu/",
                        data: {},
                        success: function(r) {
                            layer.msg('执行成功,请稍后…', { icon: 1 });
                        }
                    });
                    // location.href = prefix + "/pushMenu/";
                })
            }
            $(function () {
                var options = {
                    code: "id",
                    parentCode: "parentId",
                    uniqueId: "id",
                    url: prefix + "/list",
                    createUrl: prefix + "/add/{id}",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    modalName: "微信菜单",
                    columns: [
                        {
                            field: 'selectItem',
                            radio: true
                        },
                        {
                            field: 'name',
                            title: '菜单标题',
                            sortable: true
                        },

                        {
                            field: 'menuType',
                            title: '菜单的响应动作类型',
                            sortable: true
                        },
                        {
                            field: 'menuKey',
                            title: '菜单KEY值',
                            sortable: true
                        },
                        {
                            field: 'url',
                            title: '网页 链接',
                            sortable: true
                        },
                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var actions = [];
                                actions.push('<a class="btn btn-success btn-xs " href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-info  btn-xs" href="#" onclick="$.operate.add(\'' + row.id + '\')"><i class="fa fa-plus">新增</i></a> ');
                                actions.push('<a class="btn btn-danger btn-xs " href="#" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                return actions.join('');
                            }
                        }]
                };
                $.treeTable.init(options);

                function remove(id) {
                    $.modal.confirm("确定删除该条" + $.table._option.modalName + "信息吗？", function () {
                        $.ajax({
                            type: 'post',
                            url: prefix + "/remove/" + id,
                            success: function (result) {
                                if (result.code == web_status.SUCCESS) {
                                    $.modal.msgSuccess(result.msg);
                                    $.treeTable.refresh();
                                } else {
                                    $.modal.msgError(result.msg);
                                }
                            }
                        });
                    });
                }

            });
        </script>
    </body>
</html>